# ESP32工具链定义,基于 esp-idf-v4.4/tools/cmake/toolchain-esp32.cmake 修改
# author guyadong
# date 2024/08/24


set(CMAKE_C_FLAGS "-mlongcalls -Wno-frame-address" CACHE STRING "C Compiler Base Flags")
set(CMAKE_CXX_FLAGS "-mlongcalls -Wno-frame-address" CACHE STRING "C++ Compiler Base Flags")

# IDF_PATH 环境变量为ESP-IDF的安装位置,执行export.sh(.bat)脚本即会定义
if(NOT $ENV{IDF_PATH} STREQUAL "")
    set(IDF_PATH $ENV{IDF_PATH})
endif()
if(NOT IDF_PATH)
	message(FATAL_ERROR "NOT DEFINE SDK PREFIX FOR CROSS COMIPILER")
endif()
# 查找esp32 sdk中cJSON头文件
find_file( CJSON_HEADER cJSON.h PATHS ${IDF_PATH}/components/json/cJSON NO_DEFAULT_PATH)
if(CJSON_HEADER)
	message(STATUS "FOUND cJSON.h: ${CJSON_HEADER}")
else()
	message(FATAL_ERROR "NOT FOUND cJSON.h")
endif()
# thmar 需要cJSON库支持,所以这里需要将ESP32 SDK中cJSON头文件夹加入搜索路径
# thmar 需要esp_mqtt库支持,所以这里需要将ESP32 SDK中esp-mqtt头文件夹加入搜索路径
include_directories(
	${IDF_PATH}/components/mqtt/esp-mqtt/include
	${IDF_PATH}/components/json/cJSON
	${IDF_PATH}/components/esp_common/include
	${IDF_PATH}/components/esp_event/include
	${IDF_PATH}/components/mqtt/esp-mqtt/include
	${IDF_PATH}/components/freertos/include
	${IDF_PATH}/components/freertos/include/esp_additions/freertos
	${IDF_PATH}/components/freertos/port/xtensa/include
	${IDF_PATH}/components/heap/include
	${IDF_PATH}/components/xtensa/include
	${IDF_PATH}/components/xtensa/esp32/include
	${IDF_PATH}/components/spi_flash/sim/sdkconfig
	${IDF_PATH}/components/esp_rom/include
	${IDF_PATH}/components/soc/esp32/include
	${IDF_PATH}/components/esp_hw_support/include
	${IDF_PATH}/components/hal/include
	${IDF_PATH}/components/hal/esp32/include
	${IDF_PATH}/components/soc/include
	${IDF_PATH}/components/esp_system/include
	${IDF_PATH}/components/esp_timer/include
	${IDF_PATH}/components/newlib/platform_include
	${IDF_PATH}/components/esp_wifi/include
	${IDF_PATH}/components/esp_netif/include
)
# thmar 增加freertos库支持
# FREERTOS 定义,用于freertos库支持
# NO_FILL_SEND_TIME 关闭 MqInvoker.createEnvelope函数中发送时间的填充
add_definitions(-DFREERTOS -DNO_FILL_SEND_TIME)